package com.qf.springbootshiro.user.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.springbootshiro.user.entity.User;
import com.qf.springbootshiro.user.service.UserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping
public class VueTestController {
    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public Map<String, Object> login(String username, String password) {
        Subject subject = SecurityUtils.getSubject();
        subject.login(new UsernamePasswordToken(username, password));
        Map<String, Object> map = new HashMap<>();
        map.put("aaa", 111);
        map.put("bbb", 222);
        map.put("ccc", 333);
        return map;
    }

    @PostMapping("test1")
    public Map<String, Object> test1(@RequestBody User u) {
        System.out.println("id:" + u.getId() + "\tusername:" + u.getUsername());
        QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
        userQueryWrapper.eq("id", u.getId()).eq("username", u.getUsername());
        User user = userService.getOne(userQueryWrapper);
        Map<String, Object> map = new HashMap<>();
        map.put("code", 1);
        map.put("msg", "ok");
        map.put("data", user);
        return map;
    }
}
